/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('trafficfxopen', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model ConvertUrlHeaders {
  commonHeaders?: map[string]string,
  xAcsAirticketAccessToken?: string(name='xAcsAirticketAccessToken', description='token

This parameter is required.', example='eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpc3RyaWJ1dGlvbl9rZXlpZCJ9.eyJqdGkiOiI2cDQwZDctSDQ0dUJicEJkYTZadzdBIiwiaWF0IjoxNzI0MzE2MzM1LCJleHAiOjE3MjQzMjM1MzUsIm5iZiI6MTcyNDMxNjI3NSwiYXBwS2V5IjoiNjE3NzgxZDQxM2FmNGRlZGFiNzkifQ.XtjSM7qVbESvt7n31RtD5Pp6854IVyGMEco4aEruMDMkrXHkcdZejyecKFx3RdsCldZPgvowc5EOl44c3JJfm6DENH4M6BRBSc90eqXYcD_xVJ9FhDWzK9O6OnkvR7HX1t-qqMdikLviM1w1G0DGMLaasvZ8MPMewL8k6NnvOSGePwUhb-m5IZ14VYv7BPO2dp8Jh00qNSJQrmNiWWzJUtK_xllNr3LKQ7cIVtPgFUckvRDw9Hal5oACXSRdkZFOAGlFSjpB_BbTpe5vc-AJ8K89nRD53sIy9YyVQClV_HH7PrXxFFJgReGvNsnP1h9gf55q86IzOQBkj9vGm2zXdw', nullable=false),
  xAcsAirticketLanguage?: string(name='xAcsAirticketLanguage', example='en_US', nullable=true),
}

model ConvertUrlRequest {
  countryCallingCode?: string(name='countryCallingCode', example='+86'),
  jumpUrl?: string(name='jumpUrl', description='This parameter is required.', example='https%3A%2F%2Fmarket.wapa.taobao.com%2Fapp%2Ftrip%2Frx-traffic%2Fpages%2Fota%3F_F_sht_sm%3D12345678%26leaveFlightNo%3DCZ6132%26arrCityCode%3DDLC%26arrCityName%3D%25E5%25A4%25A7%25E8%25BF%259E%26leaveCabinClass%3D0%26itemParams%3DmQZ4eyJhZHRQcmljZSI6MzEyLCJhZnRlclByb21vdGlvbgUamFNlYXJjaCI6dHJ1ZSwiYWdlbnRJZCI6IjUwNTUiLCJhdmVyYWdlUAFFdFNob3ciOmZhbHNlLCJjYWJpbiI6IloiLCJjaGlsZAVODWgUZmlyc3RDASJkQ2xhc3MiOiJBTExfQ0FCSU4iLCJpbmZhbnQNMMgxNDAsIml0ZW1JZCI6IjEyZDJhZTdiMzk0ZjQ5MWY5MjE2ZjQzMzBjYjdkY2E5XzY2IiwFL_BCVHlwZSI6MSwibGVhdmVGbGlnaHRObyI6IkNaNjEzMiIsInByZVF1ZXJ5VGltZXN0YW1wIjoxNzI1MzQyMzI0MDU3LAEiEFRyYWNlBXscMjEwM2EzNDAVJDQwNDM3MjEyNmQzZTY4IgFQLjgBFCI6MCwicyU9GFNlZ21lbnQB53hbe1wiYXJyQ2l0eUNvZGVcIjpcIkRMQ1wiLFwiZGVwMhgACEJKUxEYCERhdAksODIwMjQtMTAtMTRcIn1dIgFiDGxlY3QJ3xhIYXNTdG9wNYMAcwUcBGVkRoAAGEFpcnBvcnRCgwBqmwA-MwAIUEtYEZ6qtgAgIDA4OjMwOjAwBTwoam91cm5leVNlcVwhLyhcIm1hcmtldGluZwnRBE5vJSEpshHxFHVwcGx5QVWIFCxbNTQ0NyULBRoQT2ZmZXJRrx0TsExpbmtlZElkIjoiYTAzOTk4MzZkZGUzNDBhMTlhZGQ2NzU4ZDZkNjQ1YjEifQ%253D%253D%26depCityName%3D%25E5%258C%2597%25E4%25BA%25AC%26leaveDate%3D2024-10-14%26fpt%3Dta.fx%2528017595%2529017595%26_fli_webview%3Dfalse%26ttid%3Ddidi.000017598%26depCityCode%3DBJS'),
  phone?: string(name='phone', description='This parameter is required.'),
  scene?: string(name='scene', description='This parameter is required.', example='1'),
  source?: string(name='source', description='This parameter is required.', example='1'),
  thirdId?: string(name='thirdId', example='2215112050977'),
  uid?: string(name='uid', description='This parameter is required.', example='123456789'),
  xenv?: string(name='xenv', description='This parameter is required.', example='1'),
}

model ConvertUrlResponseBody = {
  data?: {
    appId?: string(name='appId', example='wx6a96c49f29850eb5'),
    authUrl?: string(name='authUrl', example='https://fx.wapa.taobao.com/connect?return_url=https%3A%2F%2Fmarket.wapa.taobao.com%2Fapp%2Ftrip%2Frx-traffic%2Fpages%2Fota%3F_F_sht_sm%3D12345678%26leaveFlightNo%3DCZ6132%26arrCityCode%3DDLC%26arrCityName%3D%25E5%25A4%25A7%25E8%25BF%259E%26leaveCabinClass%3D0%26itemParams%3DmQZ4eyJhZHRQcmljZSI6MzEyLCJhZnRlclByb21vdGlvbgUamFNlYXJjaCI6dHJ1ZSwiYWdlbnRJZCI6IjUwNTUiLCJhdmVyYWdlUAFFdFNob3ciOmZhbHNlLCJjYWJpbiI6IloiLCJjaGlsZAVODWgUZmlyc3RDASJkQ2xhc3MiOiJBTExfQ0FCSU4iLCJpbmZhbnQNMMgxNDAsIml0ZW1JZCI6IjEyZDJhZTdiMzk0ZjQ5MWY5MjE2ZjQzMzBjYjdkY2E5XzY2IiwFL_BCVHlwZSI6MSwibGVhdmVGbGlnaHRObyI6IkNaNjEzMiIsInByZVF1ZXJ5VGltZXN0YW1wIjoxNzI1MzQyMzI0MDU3LAEiEFRyYWNlBXscMjEwM2EzNDAVJDQwNDM3MjEyNmQzZTY4IgFQLjgBFCI6MCwicyU9GFNlZ21lbnQB53hbe1wiYXJyQ2l0eUNvZGVcIjpcIkRMQ1wiLFwiZGVwMhgACEJKUxEYCERhdAksODIwMjQtMTAtMTRcIn1dIgFiDGxlY3QJ3xhIYXNTdG9wNYMAcwUcBGVkRoAAGEFpcnBvcnRCgwBqmwA-MwAIUEtYEZ6qtgAgIDA4OjMwOjAwBTwoam91cm5leVNlcVwhLyhcIm1hcmtldGluZwnRBE5vJSEpshHxFHVwcGx5QVWIFCxbNTQ0NyULBRoQT2ZmZXJRrx0TsExpbmtlZElkIjoiYTAzOTk4MzZkZGUzNDBhMTlhZGQ2NzU4ZDZkNjQ1YjEifQ%253D%253D%26depCityName%3D%25E5%258C%2597%25E4%25BA%25AC%26leaveDate%3D2024-10-14%26fpt%3Dta.fx%2528017595%2529017595%26_fli_webview%3Dfalse%26ttid%3Ddidi.000017598%26depCityCode%3DBJS&fliggy_scene=didi'),
    status?: {
      code?: string(name='code', example='200'),
      errorMsg?: string(name='errorMsg'),
    }(name='status', description='This parameter is required.', nullable=false),
    version?: string(name='version', example='1.0.0'),
  }(name='data'),
  errorCode?: string(name='errorCode', example='success'),
  errorData?: {
    rawErrorCode?: string(name='rawErrorCode', example='1001'),
    rawErrorMsg?: string(name='rawErrorMsg'),
  }(name='errorData'),
  errorMsg?: string(name='errorMsg'),
  requestId?: string(name='requestId', description='Id of the request', example='6BD708D6-1A8C-5CF9-85B8-D620F314F1F0'),
  success?: boolean(name='success', description='This parameter is required.', example='True'),
}

model ConvertUrlResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: ConvertUrlResponseBody(name='body'),
}

/**
 * @summary 转换联登链接
 *
 * @param request ConvertUrlRequest
 * @param headers ConvertUrlHeaders
 * @param runtime runtime options for this request RuntimeOptions
 * @return ConvertUrlResponse
 */
async function convertUrlWithOptions(request: ConvertUrlRequest, headers: ConvertUrlHeaders, runtime: Util.RuntimeOptions): ConvertUrlResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.countryCallingCode)) {
    body['countryCallingCode'] = request.countryCallingCode;
  }
  if (!Util.isUnset(request.jumpUrl)) {
    body['jumpUrl'] = request.jumpUrl;
  }
  if (!Util.isUnset(request.phone)) {
    body['phone'] = request.phone;
  }
  if (!Util.isUnset(request.scene)) {
    body['scene'] = request.scene;
  }
  if (!Util.isUnset(request.source)) {
    body['source'] = request.source;
  }
  if (!Util.isUnset(request.thirdId)) {
    body['thirdId'] = request.thirdId;
  }
  if (!Util.isUnset(request.uid)) {
    body['uid'] = request.uid;
  }
  if (!Util.isUnset(request.xenv)) {
    body['xenv'] = request.xenv;
  }

  var realHeaders : map[string]string = {};
  if (!Util.isUnset(headers.commonHeaders)) {
    realHeaders = headers.commonHeaders;
  }
  if (!Util.isUnset(headers.xAcsAirticketAccessToken)) {
    realHeaders['xAcsAirticketAccessToken'] = Util.toJSONString(headers.xAcsAirticketAccessToken);
  }
  if (!Util.isUnset(headers.xAcsAirticketLanguage)) {
    realHeaders['xAcsAirticketLanguage'] = Util.toJSONString(headers.xAcsAirticketLanguage);
  }
  var req = new OpenApi.OpenApiRequest{ 
    headers = realHeaders,
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'ConvertUrl',
    version = '2024-08-15',
    protocol = 'HTTPS',
    pathname = `/v1/distribution/trade/convertUrl`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @summary 转换联登链接
 *
 * @param request ConvertUrlRequest
 * @return ConvertUrlResponse
 */
async function convertUrl(request: ConvertUrlRequest): ConvertUrlResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers = new ConvertUrlHeaders{};
  return convertUrlWithOptions(request, headers, runtime);
}

model GetTokenRequest {
  appKey?: string(name='appKey', description='This parameter is required.'),
  appSecret?: string(name='appSecret', description='This parameter is required.'),
}

model GetTokenResponseBody = {
  data?: {
    expireTime?: string(name='expireTime', example='7200'),
    generateTime?: string(name='generateTime', example='1724130275'),
    token?: string(name='token', description='token', example='eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpc3RyaWJ1dGlvbl9rZXlpZCJ9.eyJqdGkiOiI2cDQwZDctSDQ0dUJicEJkYTZadzdBIiwiaWF0IjoxNzI0MzE2MzM1LCJleHAiOjE3MjQzMjM1MzUsIm5iZiI6MTcyNDMxNjI3NSwiYXBwS2V5IjoiNjE3NzgxZDQxM2FmNGRlZGFiNzkifQ.XtjSM7qVbESvt7n31RtD5Pp6854IVyGMEco4aEruMDMkrXHkcdZejyecKFx3RdsCldZPgvowc5EOl44c3JJfm6DENH4M6BRBSc90eqXYcD_xVJ9FhDWzK9O6OnkvR7HX1t-qqMdikLviM1w1G0DGMLaasvZ8MPMewL8k6NnvOSGePwUhb-m5IZ14VYv7BPO2dp8Jh00qNSJQrmNiWWzJUtK_xllNr3LKQ7cIVtPgFUckvRDw9Hal5oACXSRdkZFOAGlFSjpB_BbTpe5vc-AJ8K89nRD53sIy9YyVQClV_HH7PrXxFFJgReGvNsnP1h9gf55q86IzOQBkj9vGm2zXdw'),
  }(name='data'),
  errorCode?: string(name='errorCode', example='success'),
  errorData?: {
    rawErrorCode?: string(name='rawErrorCode', example='1001'),
    rawErrorMsg?: string(name='rawErrorMsg'),
  }(name='errorData'),
  errorMsg?: string(name='errorMsg'),
  requestId?: string(name='requestId', description='Id of the request', example='6BD708D6-1A8C-5CF9-85B8-D620F314F1F0'),
  status?: int32(name='status', example='confirmed'),
  success?: boolean(name='success', example='True'),
}

model GetTokenResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: GetTokenResponseBody(name='body'),
}

/**
 * @summary 创建token
 *
 * @param request GetTokenRequest
 * @param headers map
 * @param runtime runtime options for this request RuntimeOptions
 * @return GetTokenResponse
 */
async function getTokenWithOptions(request: GetTokenRequest, headers: map[string]string, runtime: Util.RuntimeOptions): GetTokenResponse {
  Util.validateModel(request);
  var query : map[string]any = {};
  if (!Util.isUnset(request.appKey)) {
    query['appKey'] = request.appKey;
  }
  if (!Util.isUnset(request.appSecret)) {
    query['appSecret'] = request.appSecret;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'GetToken',
    version = '2024-08-15',
    protocol = 'HTTPS',
    pathname = `/v1/distribution/trade/getToken`,
    method = 'GET',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @summary 创建token
 *
 * @param request GetTokenRequest
 * @return GetTokenResponse
 */
async function getToken(request: GetTokenRequest): GetTokenResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return getTokenWithOptions(request, headers, runtime);
}

model SearchHeaders {
  commonHeaders?: map[string]string,
  xAcsAirticketAccessToken?: string(name='xAcsAirticketAccessToken', description='token

This parameter is required.', example='eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpc3RyaWJ1dGlvbl9rZXlpZCJ9.eyJqdGkiOiI2cDQwZDctSDQ0dUJicEJkYTZadzdBIiwiaWF0IjoxNzI0MzE2MzM1LCJleHAiOjE3MjQzMjM1MzUsIm5iZiI6MTcyNDMxNjI3NSwiYXBwS2V5IjoiNjE3NzgxZDQxM2FmNGRlZGFiNzkifQ.XtjSM7qVbESvt7n31RtD5Pp6854IVyGMEco4aEruMDMkrXHkcdZejyecKFx3RdsCldZPgvowc5EOl44c3JJfm6DENH4M6BRBSc90eqXYcD_xVJ9FhDWzK9O6OnkvR7HX1t-qqMdikLviM1w1G0DGMLaasvZ8MPMewL8k6NnvOSGePwUhb-m5IZ14VYv7BPO2dp8Jh00qNSJQrmNiWWzJUtK_xllNr3LKQ7cIVtPgFUckvRDw9Hal5oACXSRdkZFOAGlFSjpB_BbTpe5vc-AJ8K89nRD53sIy9YyVQClV_HH7PrXxFFJgReGvNsnP1h9gf55q86IzOQBkj9vGm2zXdw'),
  xAcsAirticketLanguage?: string(name='xAcsAirticketLanguage', example='en_US'),
}

model SearchRequest {
  scene?: string(name='scene'),
  searchParam?: string(name='searchParam', description='This parameter is required.', example='{
  "cabinClass": "ALL_CABIN",
  "passengerTypeQuantity": {
    "ADT": 1,
    "INFANT": 0,
    "CHD": 0
  },
  "searchMode": 0,
  "searchOdInfoList": [
    {
      "arrCityCode": "BJS",
      "depCityCode": "JNG",
      "depDate": "2024-08-14 00:00:00"
    }
  ],
  "searchSource": "gd",
  "tripType": 1
}'),
  source?: string(name='source', description='This parameter is required.', example='“1”'),
  terminal?: string(name='terminal', description='This parameter is required.', example='“1”'),
  userId?: string(name='userId', example='“121343”'),
}

model SearchResponseBody = {
  data?: string(name='data', description='This parameter is required.'),
  errorCode?: string(name='errorCode', example='success'),
  errorData?: {
    rawErrorCode?: string(name='rawErrorCode', example='1001'),
    rawErrorMsg?: string(name='rawErrorMsg'),
  }(name='errorData'),
  errorMsg?: string(name='errorMsg'),
  requestId?: string(name='requestId', description='Id of the request', example='71ad3e90-53f8-445b-be9d-df91039cba47'),
  success?: boolean(name='success', example='true'),
}

model SearchResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: SearchResponseBody(name='body'),
}

/**
 * @summary 分销报价接口
 *
 * @param request SearchRequest
 * @param headers SearchHeaders
 * @param runtime runtime options for this request RuntimeOptions
 * @return SearchResponse
 */
async function searchWithOptions(request: SearchRequest, headers: SearchHeaders, runtime: Util.RuntimeOptions): SearchResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.scene)) {
    body['scene'] = request.scene;
  }
  if (!Util.isUnset(request.searchParam)) {
    body['searchParam'] = request.searchParam;
  }
  if (!Util.isUnset(request.source)) {
    body['source'] = request.source;
  }
  if (!Util.isUnset(request.terminal)) {
    body['terminal'] = request.terminal;
  }
  if (!Util.isUnset(request.userId)) {
    body['userId'] = request.userId;
  }

  var realHeaders : map[string]string = {};
  if (!Util.isUnset(headers.commonHeaders)) {
    realHeaders = headers.commonHeaders;
  }
  if (!Util.isUnset(headers.xAcsAirticketAccessToken)) {
    realHeaders['xAcsAirticketAccessToken'] = Util.toJSONString(headers.xAcsAirticketAccessToken);
  }
  if (!Util.isUnset(headers.xAcsAirticketLanguage)) {
    realHeaders['xAcsAirticketLanguage'] = Util.toJSONString(headers.xAcsAirticketLanguage);
  }
  var req = new OpenApi.OpenApiRequest{ 
    headers = realHeaders,
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'Search',
    version = '2024-08-15',
    protocol = 'HTTPS',
    pathname = `/v1/distribution/trade/search`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @summary 分销报价接口
 *
 * @param request SearchRequest
 * @return SearchResponse
 */
async function search(request: SearchRequest): SearchResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers = new SearchHeaders{};
  return searchWithOptions(request, headers, runtime);
}

